﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css?v=318">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body>
    <!-- 主体部分 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">
                <div class="layui-btn-group" style="margin-top:5px">
                    <button type="button" class="layui-btn " id="saveBtn">
                        <i class="layui-icon">&#xe655;</i> 保存当前
                    </button>
                    <button type="button" class="layui-btn  layui-btn-primary" id="refreshBtn">
                        <i class="layui-icon">&#xe666;</i> 还原当前
                    </button>
                </div>

            </div>

            <div class="layui-card-body">

                <div class="layui-tab layui-tab-brief" lay-filter="TabBrief">
                    <script id="codeList" type="text/html" ew-tpl="codeList">
                        <ul class="layui-tab-title">
                            {{# if(d){ }} <!-- 这里判断以下因为可能值还没定义 -->
                            {{# layui.each(d,function(i,item){ }}
                            {{# if(i == 0){ }}
                            <li class="layui-this">{{item}}</li>
                            {{# } else { }}
                            <li>{{item}}</li>
                            {{# } }}
                            {{# }); }}
                            {{# } }}
                        </ul>
                    </script>
                    <script id="codeStrs" type="text/html" ew-tpl="codeStrs">
                        <div class="layui-tab-content">
                            {{# if(d){ }} <!-- 这里判断以下因为可能值还没定义 -->
                            {{# layui.each(d,function(i,item){ }}
                            {{# if(i == 0){ }}
                            <div class="layui-tab-item layui-show">
                                <textarea id="code_{{i}}" class="layui-textarea" style="min-height:400px;max-height:800px;">{{item}}</textarea>
                            </div>
                            {{# } else { }}
                            <div class="layui-tab-item">
                                <textarea id="code_{{i}}" class="layui-textarea" style="min-height:400px;max-height:800px;">{{item}}</textarea>
                            </div>
                            {{# } }}
                            {{# }); }}
                            {{# } }}
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>

    <!-- 加载动画 -->
    <div class="page-loading">
        <div class="signal-loader">
            <span></span><span></span><span></span><span></span>
        </div>
    </div>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script src="/assets/js/main.js"></script>
    <script>
        layui.use(['layer', 'form', 'table', 'util', 'admin', 'setter', 'element'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var util = layui.util;
            var admin = layui.admin;
            var setter = layui.setter;
            var element = layui.element;

            var tabIndex = 0;
            var arr;

            function init() {
                admin.req('/SystemManage/CodeTemplet/GetListJson', function (res) {
                    // 移除loading
                    admin.removeLoading();

                    if (res.Tag == 1) {
                        window.codeList = res.Data.map(function (d) { return d.Remark; });
                        window.codeStrs = res.Data.map(function (d) { return d.Code; });
                        admin.renderTpl('#codeList');
                        admin.renderTpl('#codeStrs');
                        arr = res.Data;
                    } else {
                        layer.msg(res.Message, { icon: 2, time: false });
                    }
                });
            }

            // 按钮切换
            element.on('tab(TabBrief)', function (data) {
                tabIndex = data.index;
            });

            // 初始化
            init();

            // 保存按钮
            $('#saveBtn').click(function () {
                admin.showLoading('body', 3, '.8');
                var item = arr[tabIndex];
                item.Code = $("#code_" + tabIndex).val();

                admin.req('/SystemManage/CodeTemplet/SaveFormJson', item, function (res) {
                    admin.removeLoading('body', true, true);
                    if (res.Tag == 1) {
                        layer.msg('操作成功', { icon: 1, time: 1500 });
                    }
                    else {
                        layer.msg(res.Message, { icon: 2 });
                    }
                }, 'post');
            });

            $('#refreshBtn').click(function () {
                $("#code_" + tabIndex).val(arr[tabIndex].Code);
                layer.msg('操作成功', { icon: 1, time: 1500 });
            });

        });
    </script>
</body>
</html>